String.format = function() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    if(arguments.length == 1) {
        return str;
    }

    var params = arguments[1];

    if(params && typeof params == "object" && arguments.length == 2) {
        var groups = str.match("\\{([^}]+)\\}");
        while (groups) {
            str = str.replace(groups[0], params[groups[1]]);
            groups = str.match("\\{([^}]+)\\}");
        }
    } else {
        for ( var i = 1; i < arguments.length; i ++) {
            var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
            str = str.replace(re, arguments[i]);
        }
    }
    return str;
};

String.prototype.replaceAll = function(s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2); //g全局
};

String.prototype.startsWith = function(searchString, position) {
	position = position || 0;
	return this.indexOf(searchString, position) === position;
};

String.prototype.endsWidth = function(searchString) {
	if(!searchString) {
		return false;
	}
	var position = this.length - searchString.length;
	return this.indexOf(searchString, position) === position;
};